﻿@using SCMS.Resource
@model SCMS.UI.Models.ViewSalaryPayment
<div class="partialViewCard">
    <div class="partialViewCardHeader">
        <h3>
            @Resources.Global_String_SPM: @Model.EntitySalaryP.RefNumber</h3>
    </div>
    @if (Model.CanEdit)
    {
        <center>
            @Ajax.ActionLink(Resources.Global_String_Edit + " " + Resources.Global_String_SPM, "EditSPM", new AjaxOptions
            {
                UpdateTargetId = "SPtDiv",
                LoadingElementId = "loading",
                Url = Url.Action("EditSPM/" + Model.EntitySalaryP.Id)
            }) |
            @Ajax.ActionLink(Resources.Global_String_Delete + " " + Resources.Global_String_ECF, "DeleteECF", new AjaxOptions
       {
           UpdateTargetId = "SPtDiv",
           LoadingElementId = "loading",
           Url = Url.Action("DeleteSPM/" + Model.EntitySalaryP.Id),
           Confirm = "Delete '" + Model.EntitySalaryP.RefNumber + "'?",
           OnSuccess = "usermsg('" + Resources_frank.SalaryPayment_String_DeleteSuccessMessage + "');if(document.getElementById('table') != null){initSorter();sorter.size(50);}"
       })
        </center>
    }
    else if (Model.CanApprove)
    {
        string linkText = null;
        string actionName = null;
        if (Model.EntitySalaryP.IsReviewed && !Model.EntitySalaryP.IsAuthorized && !Model.EntitySalaryP.IsRejected)
        {
            linkText = Resources.SalaryPayment_String_AuthorizeSalaryPayment;
            actionName = "LoadSPMForAuth";
        }
        else if (Model.EntitySalaryP.IsSubmitted && !Model.EntitySalaryP.IsReviewed && !Model.EntitySalaryP.IsRejected)
        {
            linkText = Resources.SalaryPayment_String_ReviewSalaryPayment;
            actionName = "ReviewSPM";
        }
        if (linkText != null)
        {
            <center id="canApprove">
                @Ajax.ActionLink(linkText, actionName, "RequestReview", new { id = "" }, new AjaxOptions
           {
               OnBegin = "ShowDialogueOR('" + linkText + ": " + Model.EntitySalaryP.RefNumber + "')",
               UpdateTargetId = "popup-page",
               LoadingElementId = "popup-loading",
               Url = Url.Action(actionName + "/" + Model.EntitySalaryP.Id, "RequestReview"),
               OnSuccess = "CenterPopupSPM();document.getElementById('canApprove').innerHTML ='&nbsp;';"
           }) 
            </center>
        }
    }
    else
    {
        <br />
    }
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th align="center">
                @Resources.SalaryPayment_String_PayrollMonth
            </th>
            <th align="center">
                @Resources.SalaryPayment_String_PayrollYear
            </th>
            <th align="center">
                @Resources.Global_String_Date
            </th>
        </tr>
        <tr class="gridodd">
            <td align="center">
                @Model.EntitySalaryP.PayrollMonth
            </td>
            <td align="center">
                @Model.EntitySalaryP.PayrollYear
            </td>
            <td align="center">
                @Model.EntitySalaryP.PayrollDate.Value.ToString("dd/MM/yyyy")
            </td>
        </tr>
        <tr class="gridheader">
            <th align="center">
                @Resources.Global_String_Office
            </th>
            <th align="center">
                @Resources.Global_String_Currency
            </th>
            <th align="center">
                @Resources.SalaryPayment_String_TotalPayrollPayment
            </th>
        </tr>
        <tr class="gridodd">
            <td align="center">
                @Model.EntitySalaryP.CountrySubOffice.Name
            </td>
            <td align="center">
                @Model.EntitySalaryP.Currency.ShortName
            </td>
            <td align="center">
                @Model.EntitySalaryP.TotalPayroll.ToString("##,##0.00")
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_SubjectPurpose:
            </td>
            <td colspan="2">
                @Model.EntitySalaryP.Subject
            </td>
        </tr>
    </table>
    <br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th colspan="5" align="center">
                @Resources.SalaryPayment_String_PayrollDetails
            </th>
        </tr>
        <tr class="gridheader">
            <th colspan="2">
                @Resources.Payroll_Edit_PayrollItem
            </th>
            <th>
                @Resources.Budget_CategoryList_ProjectNo
            </th>
            <th>
                @Resources.Budget_CreateSubLine_LineNumber
            </th>
            <th>
                @Resources.Global_String_Amount
            </th>
        </tr>
        @foreach (var item in Model.EntitySalaryP.SalaryBudgetlines)
        {
            <tr class="gridodd">
                <td style="width: 41%; text-align: left;" colspan="2">
                    @item.PayrollItem.Name
                </td>
                <td style="width: 19%; text-align: left;">
                    @item.ProjectBudget.BudgetCategory.ProjectDonor.ProjectNumber
                </td>
                <td style="width: 19%; text-align: left;">
                    @item.ProjectBudget.LineNumber
                </td>
                <td style="width: 19%; text-align: right;">
                    @item.Amount.ToString("##,##0.00")
                </td>
            </tr>
        }
        <tr>
            <td class="gridheader" style="width: 22%;">
                @Resources.Global_String_MasterBudgetCurrency
            </td>
            <td align="center" style="width: 19%;">
            </td>
            <td class="gridheader" style="width: 19%;">
                @Resources.Global_String_Total
            </td>
            <td align="right" style="width: 19%;">
            </td>
            <td class="gridheader" style="width: 19%;">
                @Resources.SalaryPayment_String_SalaryPaymentValue
            </td>
        </tr>
    </table>
    @if (Model.CanPostFunds)
    { 
        <table width="98%" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td align="right" width="100%" style="padding: 3px 0px 0px 0px">
                    <input type="button" id="btnPost" name="btnPost" value="@Resources.Global_String_PostFunds" class="btn tertiary" onclick="ShowDialogue('@Resources.Global_String_AuthenticateFundsPoster'); sendRequest('/FundPosting/PostSPM/@Model.EntitySalaryP.Id', 'popup-page', 'popup-loading'); CenterPopup();" />
                </td>
            </tr>
        </table>
    }
    else
    {    
        <br /> 
    }
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <td>
                @Resources.Approver_ApproverList_Authorization
            </td>
            <td>
                @Resources.Global_String_PreparedBy
            </td>
            <td>
                @Resources.Global_String_FinanceReviewOfBL
            </td>
            <td>
                @Resources.Global_String_AuthorizedByManager
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Name:
            </td>
            <td>
                @Model.PreparedBy.StaffName
            </td>
            <td>
                @if (Model.ApprovedBy != null)
                { @Model.ApprovedBy.StaffName}
            </td>
            <td>
                @if (Model.AuthorizedBy != null)
                { @Model.AuthorizedBy.StaffName}
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Title:
            </td>
            <td>
                @Model.PreparedBy.Designation
            </td>
            <td>
                @if (Model.ApprovedBy != null)
                { @Model.ApprovedBy.Designation}
            </td>
            <td>
                @if (Model.AuthorizedBy != null)
                { @Model.AuthorizedBy.Designation}
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Date:
            </td>
            <td>
                @Model.EntitySalaryP.PreparedOn.Value.ToString("dd/MM/yyyy h:mm tt")
            </td>
            <td>
                @if (Model.EntitySalaryP.ReviewedOn != null)
                {
                    @Model.EntitySalaryP.ReviewedOn.Value.ToString("dd/MM/yyyy h:mm tt")
                }   
            </td>
            <td>
                @if (Model.EntitySalaryP.AuthorizedOn != null)
                { 
                    @Model.EntitySalaryP.AuthorizedOn.Value.ToString("dd/MM/yyyy h:mm tt")
                }                
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Signature:
            </td>
            <td>
                @if (Model.EntitySalaryP.Staff2 != null && Model.EntitySalaryP.Staff2.Person.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.EntitySalaryP.Staff2.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                }
            </td>
            <td>
                @if (Model.EntitySalaryP.Staff3 != null && Model.EntitySalaryP.Staff3.Person.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.EntitySalaryP.Staff3.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                }
            </td>
            <td>
                @if (Model.EntitySalaryP.Staff1 != null && Model.EntitySalaryP.Staff1.Person.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.EntitySalaryP.Staff1.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                }
            </td>
        </tr>
    </table>
    
    @if (Model.EntitySalaryP.IsAuthorized)
    {
        <hr />
        <center>
            <a class="btn btn-primary" href="@Url.Action("pdf", "SP", new { area = "Reports", SPid = Model.EntitySalaryP.Id })" target="_blank" style="margin-left: 48%; margin-bottom: 2%;">
                @Resources.Budget_ViewBudget_DownloadPdf</a>
        </center>
    }
    else if (Model.CanEdit && Model.EntitySalaryP.SalaryBudgetlines != null && Model.EntitySalaryP.SalaryBudgetlines.Count > 0)
    { 
        <br />
        <table width="98%" cellspacing="0" cellpadding="0">
            <tr>
                <td width="100%" align="right">
                    <input type="button" class="btn green" value="  @Resources.Global_String_SubmitForReview  " onclick="if(confirm('@Resources.Global_String_SubmitForReview?')){ sendRequest('SubmitSPM/@Model.EntitySalaryP.Id', 'SPtDiv', 'loading'); if (document.getElementById('table') != null) {initSorter();sorter.size(50);}}" />
                </td>
            </tr>
        </table>
    }
    <br />
</div>
<br />
<p>
    @Ajax.ActionLink(Resources.Global_String_BackToList, "Index", new { id = "ViewSalaryPayment" }, new AjaxOptions
    {
        UpdateTargetId = "SPtDiv",
        LoadingElementId = "loading",
        Url = Url.Action("ViewSalaryPayment"),
        OnSuccess = "initSorter();sorter.size(50);"
    })
</p>
